package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.tongdun.TongDunAddrFrequencyRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 朴道-同盾地址画像活跃度
 *
 * @author guoqiang
 */

public class TongDunAddrFrequencyParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 朴道-同盾地址画像活跃度
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        TongDunAddrFrequencyRecord obj = (TongDunAddrFrequencyRecord) model;
        StringBuilder sb = getBaseInfo(obj, successful);

        StringBuilder TxSb = new StringBuilder(500);
        TxSb.append(formatValue(obj.getName())).append(CRT001);
        TxSb.append(formatValue(obj.getFlag())).append(CRT001);
        TxSb.append(formatValue(obj.getResult())).append(CRT001);
        TxSb.append(formatValue(obj.getSuccess())).append(CRT001);
        TxSb.append(formatValue(obj.getTop1AddrWaybillNumLast3M())).append(CRT001);
        TxSb.append(formatValue(obj.getTop1AddrWaybillNumLast6M())).append(CRT001);
        TxSb.append(formatValue(obj.getTop1AddrWaybillNumLast1Y())).append(CRT001);
        TxSb.append(formatValue(obj.getTop1AddrWaybillFeeLast3M())).append(CRT001);
        TxSb.append(formatValue(obj.getTop1AddrWaybillFeeLast6M())).append(CRT001);
        TxSb.append(formatValue(obj.getTop1AddrWaybillFeeLast1Y())).append(CRT001);
        TxSb.append(formatValue(obj.getTop1AddrInsuredNumLast3M())).append(CRT001);
        TxSb.append(formatValue(obj.getTop1AddrInsuredNumLast6M())).append(CRT001);
        TxSb.append(formatValue(obj.getTop1AddrInsuredNumLast1Y())).append(CRT001);
        TxSb.append(formatValue(obj.getTop1AddrUseDaysLast3M())).append(CRT001);
        TxSb.append(formatValue(obj.getTop1AddrUseDaysLast6M())).append(CRT001);
        TxSb.append(formatValue(obj.getTop1AddrUseDaysLast1Y())).append(CRT001);
        key.set(getKey());
        val.set((sb.toString() + TxSb).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_tong_dun_addr_frequency_inc";
    }

    @Override
    public String getType() {
        return RecordType.PD_TONGDUN_ADDR_FREQUENCY_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "朴道-同盾地址画像活跃度";
    }
}
